<%@ page language="java" import="java.util.*,com.hanma.bean.*" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Insert title here</title>
    <script type="text/javascript" src="/message/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" src="/message/ueditor/ueditor.all.js"></script>
</head>
<body>
<%
    News news = (News)request.getAttribute("news");
%>
<form action="newsupdateAction.do?id=<%=news.getId()%>" method="post">
    <table border="1" align="center" cellspacing="0" cellpadding="0" width="600">
        <tr align="center" height="50">
            <td colspan="3">新闻添加</td>
        </tr>
        <tr width="100" align="center" height="50">
            <td >新闻名称</td>
            <td colspan="2"><input type="text" name="name" value="<%=news.getTitle()%>"></td>
        </tr>
        <tr align="center" height="50">
            <td>添加分类</td>
            <td colspan="2">
                <select name="pid1" id="j_cate_id">
                    <option  value="0">请选择一级分类</option>
                    <%
                        List<Category> cateList = (List<Category>)request.getAttribute("cateList");
                        if(cateList != null && cateList.size() > 0){
                            for(Category category : cateList){
                    %>
                    <option <%= category.getId()==news.getCateId() ? "selected" : "" %> value="<%= category.getId()%>"><%= category.getName()%></option>
                    <%
                            }
                        }
                    %>
                </select>
                <select name="pid2" id="j_seCate_id">
                    <option  value="0">请选择二级分类</option>
                </select>
            </td>
        </tr>
        <tr align="center" height="50">
            <td>新闻内容</td>
            <td colspan="2"><textarea id="container" name="content" type="text/plain" ><%=news.getContent()%></textarea></td>
        </tr>
        <tr align="center" height="50">
            <td colspan="3">
                <input type="submit" value="增加">
            </td>
        </tr>
    </table>
</form>
</body>
<script src="home/js/jquery-3.4.1.min.js"></script>
<script type="text/javascript">
    var container = UE.getEditor('container', {
        initialFrameWidth: 1000,
        initialFrameHeight: 400,
        zIndex: 1
    });
    $(function(){
        $("#j_cate_id").change(function(){
            var cateId = $(this).val()
            var url = "getCate.do"
            var postDate = {
                cateId : cateId
            }
            $.get(url,postDate,function(date){
                console.log(date)
                var html = "<option value='0'>请选择二级分类</option>"
                $(date).each(function(){
                    html += "<option value='"+this.id+"'>"+this.name+"</option>"
                })
                $("#j_seCate_id").html(html)
            },"json")
        })
    })
</script>
</html>